package com.sunfeng.chap2.p13;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @Author : 孙峰
 * @Description: 共享锁之间是非互斥的
 * @Date : 2021/10/9  18:18
 */
public class Test13_20 {
    public static void main(String[] args) {
        try {
            RandomAccessFile randomAccessFile = new RandomAccessFile("D:\\nio\\a.txt", "rw");
            FileChannel channel = randomAccessFile.getChannel();


            channel.lock(0, Long.MAX_VALUE, true);
            Thread.sleep(Integer.MAX_VALUE);

        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
